package com.chen.Dome1InetAddress;

import java.net.InetAddress;

public class InetAddressDome1 {
    public static void main(String[] args) {
        //目标：认识InetAddress类获取本机对象和远程主机对象
        try {
            InetAddress inetAddress1 = InetAddress.getLocalHost();
//            System.out.println(inetAddress1);
            System.out.println(inetAddress1.getHostAddress());
            System.out.println(inetAddress1.getHostName());
            // 通过域名获取IP地址
            InetAddress inetAddress2 = InetAddress.getByName("www.baidu.com");
            System.out.println(inetAddress2.getHostAddress());
            System.out.println(inetAddress2.getHostName());
            //判断本机和远程主机是否互通
            System.out.println(inetAddress2.isReachable(5000));// 超时时间 相当于ping命令
        }catch(Exception e){
            e.printStackTrace();
        }
    }
}
